package com.buddies.lottery.ui.wallet.pwd;

import com.buddies.lottery.base.BasePresenter;
import com.buddies.lottery.common.ConfigManager;
import com.buddies.lottery.data.BaseObserver;
import com.buddies.lottery.data.DataManager;
import com.buddies.lottery.data.resp.CheckWalletPwdResponse;
import com.buddies.lottery.ui.user.pwd.ResetPasswordContract;

/**
 * Created by xuliang on 2018/2/28.
 */

public class UpdateWalletPwdPresenter extends BasePresenter<UpdateWalletPwdContract.View> implements UpdateWalletPwdContract.Presenter {

    public UpdateWalletPwdPresenter(UpdateWalletPwdContract.View view) {
        super(view);
    }

    @Override
    public void checkWalletPwd() {
        addSubscription(DataManager.getInstance().getUserRepo().checkWalletPwd(null), new BaseObserver<CheckWalletPwdResponse>() {
            @Override
            public void onNext(CheckWalletPwdResponse response) {
                ConfigManager.getInstance().setWalletPwdExist(response.result);
                mView.onCheckWalletPwd(response);
            }

            @Override
            public void onError(Throwable e) {
                mView.onError(e);
            }
        });
    }

    @Override
    public void postUpdateWalletPwd(String oldPassword, String newPassword) {
        addSubscription(DataManager.getInstance().getUserRepo().postUpdateWalletPwd(oldPassword, newPassword), new BaseObserver<Object>() {
            @Override
            public void onNext(Object response) {
                mView.onUpdateWalletPwdSuccess();
            }

            @Override
            public void onError(Throwable e) {
               mView.onError(e);
            }
        });
    }

}
